﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_Public;
using QLTV_BLL;
using System.Diagnostics;

namespace QLTV_GiaoDien
{
    public partial class uc_TimKiemTaiLieu : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_TimKiemTaiLieu()
        {
            InitializeComponent();
        }
        TimKiem_BLL timkiem_bll = new TimKiem_BLL();
        private void uc_TimKiemTaiLieu_Load(object sender, EventArgs e)
        {
            //gridControl1.DataSource = timkiem_bll.load_TimKiemTaiLieu();
        }

        private void cob_TheLoai_Click(object sender, EventArgs e)
        {
            string sql = "select TenTheLoai from tbl_TheLoai";
            DataTable dt = new DataTable();
            dt = timkiem_bll.TaoBang(sql);
            cob_TheLoai.DataSource = dt;
            cob_TheLoai.DisplayMember = "TenTheLoai";
        }
        TaiLieu_Public tailieu = new TaiLieu_Public();
        TheLoai_public theloai = new TheLoai_public();
        private void btn_TimKiem_Click(object sender, EventArgs e)
        {
            
            //tìm kiếm tên tài liệu
            if (txt_TenTaiLieu.Text != "" && txt_TacGia.Text == "" && cob_TheLoai.Text == "")
            {
                tailieu.TenTaiLieu = txt_TenTaiLieu.Text;
                gridControl1.DataSource = timkiem_bll.TimKiem_TaiLieu_TenTaiLieu(tailieu);
            }
            //tìm kiếm tác giả
            if (txt_TenTaiLieu.Text == "" && txt_TacGia.Text != "" && cob_TheLoai.Text == "")
            {
                tailieu.TacGia = txt_TacGia.Text;
                gridControl1.DataSource = timkiem_bll.TimKiem_TaiLieu_TacGia(tailieu);
            }
            //tìm kiếm thể loại
            if (txt_TenTaiLieu.Text == "" && txt_TacGia.Text == "" && cob_TheLoai.Text != "")
            {
                theloai.TenTheLoai = cob_TheLoai.Text;
                gridControl1.DataSource = timkiem_bll.TimKiem_TaiLieu_TheLoai(theloai);
            }
            //tìm kiếm theo tên tài liệu tác giả
            if (txt_TenTaiLieu.Text != "" && txt_TacGia.Text != "" && cob_TheLoai.Text == "")
            {
                tailieu.TenTaiLieu = txt_TenTaiLieu.Text;
                tailieu.TacGia = txt_TacGia.Text;
                gridControl1.DataSource = timkiem_bll.TimKiem_TenTaiLieu_TacGia(tailieu, tailieu);
            }
            //tìm kiêm theo tên tài liệu thể loại
            if (txt_TenTaiLieu.Text != "" && txt_TacGia.Text == "" && cob_TheLoai.Text != "")
            {
                tailieu.TenTaiLieu = txt_TenTaiLieu.Text;
                theloai.TenTheLoai = cob_TheLoai.Text;
                gridControl1.DataSource = timkiem_bll.TimKiem_TenTaiLieu_TenTheloai(tailieu, theloai);
            }
            //tìm kiếm cả 3
            if (txt_TenTaiLieu.Text != "" && txt_TacGia.Text != "" && cob_TheLoai.Text != "")
            {
                tailieu.TenTaiLieu = txt_TenTaiLieu.Text;
                tailieu.TacGia = txt_TacGia.Text;
                theloai.TenTheLoai = cob_TheLoai.Text;
                gridControl1.DataSource = timkiem_bll.TimKiem_TaiLieu_Full(tailieu, tailieu, theloai);
            }
        }

        private void btn_Huy_Click(object sender, EventArgs e)
        {
            txt_TacGia.ResetText();
            txt_TenTaiLieu.ResetText();
            cob_TheLoai.ResetText();
        }

        private void txt_TenTaiLieu_TextChanged(object sender, EventArgs e)
        {
            btn_TimKiem_Click(sender,e);
        }

        private void txt_TacGia_TextChanged(object sender, EventArgs e)
        {
                btn_TimKiem_Click(sender, e);
        }
        private void cob_TheLoai_TextChanged(object sender, EventArgs e)
        {
            btn_TimKiem_Click(sender, e);
        }

        private void bbi_In_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //Process.Start("C:\\Windows\\system32\\calc");
        }

    }
}
